﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PBOffice.Models;

namespace PBOffice.DAL
{
    public class DeskFunService
    {
        public List<DeskFun> GetAllDeskFun()
        {
            List<DeskFun> list = new List<DeskFun>();
            string sql = "select * from DeskFun";
            using (SqlDataReader dr = SqlHelp.ExecuteReader(SqlHelp.connectionstring, CommandType.Text, sql))
            {
                while (dr.Read())
                {
                    DeskFun desk = new DeskFun();
                    desk.FunId = (int)dr["FunId"];
                    desk.Title = dr["Title"].ToString();
                    desk.FunPath = dr["FunPath"].ToString();
                    desk.DisplayOrder = (int)dr["DisplayOrder"];
                    list.Add(desk);
                }
            }
            return list;

        }
        public DeskFun GetDeskFunByOrder(int orderId)
        {
            DeskFun desk = new DeskFun();
            string sql = string.Format("select * from DeskFun where DisplayOrder={0}", orderId);
            using (SqlDataReader dr = SqlHelp.ExecuteReader(SqlHelp.connectionstring, CommandType.Text, sql))
            {
                while (dr.Read())
                {

                    desk.FunId = (int)dr["FunId"];
                    desk.Title = dr["Title"].ToString();
                    desk.FunPath = dr["FunPath"].ToString();
                    desk.DisplayOrder = (int)dr["DisplayOrder"];

                }
            }
            return desk;
        }
    }
}
